package com.example.itcacp.controller;

import com.example.itcacp.dto.response.Result;
import com.example.itcacp.entity.Message;
import com.example.itcacp.entity.Message.MessageType;
import com.example.itcacp.service.MessageService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/interaction")
public class InteractionController {

    @Resource
    private MessageService messageService;

    // 添加互动记录
    @PostMapping("/addInteraction")
    public Result addInteraction(@RequestBody Message message) {
        messageService.saveMessage ( message );
        return Result.success ();
    }

    // 获取互动通知列表
    @GetMapping("/list")
    public Result getInteractionList(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize,
                                     @RequestParam Long receiverId) {
        PageInfo<Message> messagesByUserIdAndType = messageService.getMessagesByUserIdAndType (pageNum, pageSize, receiverId, MessageType.CONTENT );
        // 返回内容相关的消息
        return Result.success (messagesByUserIdAndType);
    }

    // 获取互动通知详情
    @GetMapping("/detail/{id}")
    public Message getInteractionDetail(@PathVariable Long id) {
        return messageService.getMessageById(id);
    }
}